$('.detail_lanuage li').click(function(event) {
	window.location.href=URL+"business/touroute/detail/"+$('#b_id').val()+'/'+$(this).attr('data-lang')
});


// 时间段添加
function time_add(){
	$('.time_add').val('')
	var arr = []
	for (var i = 0; i < $('.period .time').length; i++) {
		var begin = $('.period .time').eq(i).find('input').eq(0).val()
		console.log(begin)
		var end  = $('.period .time').eq(i).find('input').eq(1).val()
		console.log(end)
		var O = {}
		O.begin = begin
		O.end = end
		arr[i]= O
	}
	var datas = JSON.stringify(arr)

	$('.time_add').val(datas)
}
time_add()

$('.period').on('blur', 'input', function(event) {
	time_add()
});

$('.period .time:last').append('<div class="addtime">+</div>')
$('.period').on('click','.addtime',function(event) {
	$('.time').find('.addtime').remove()
	$('.period').append('	<div class="time"><input type="text" placeholder="00:00" name=""><p class="p">-</p><input type="text" placeholder="00:00" ></div>')
	$('.period .time:last').append('<div class="addtime">+</div>')
});






// 上传路线图册
if ($('.detail_imgul img').length == 0) {
	$('.detail_imgul').hide()
	$('.detail_sss').removeClass('detail_s')
}else{
	$('.detail_imgul').show()
	$('.detail_sss').addClass('detail_s')
}

// 上传图片img
uploadimg()
function uploadimg(){
	var lengths = $('.detail_imgul li').length
	var vals = []
	for (var i = 0; i < lengths; i++) {
		var srcval = $('.detail_imgul li').eq(i).find('img').attr('src')
		vals.push(srcval)
		$('.detail_add_imginput').val('')
		$('.detail_add_imginput').val(vals)
	}
}
function ajaxFileUpload() {
	var f = document.getElementById("fileupload").files;
	
			if (f[0].size<= 2097152) {
				$.ajaxFileUpload({
					url: URL + 'business/attachment/ajax_upload_image',
					secureuri: false,
					fileElementId: 'fileupload',
					dataType:'json',
					success: function(data, status) {
						if (data.code == 200010) {
							upload();
							$('.detail_imgul').show()
							$('.detail_imgul').append('<li><img src="'+data.content.image_url+'" ><div class="detail_imguldel"><img src="'+URLs+'/images/del.png" alt="" /></div></li>')
							$('.detail_sss').addClass('detail_s');
							uploadimg()
						}else{
							alert(data.message)
						}

						
					},
					error: function(data, status, e) {
						console.log('error')
					}
				})
			}else{
				alert('文件太大')
			}

	return false;
}

$('.detail_add_img').on('click','.detail_imguldel',function(event) {
	$(this).parents('li').remove()
	uploadimg()
});
// 初始化图册上传控件
var upload = function() {
	$('#fileupload').change(function(event) {
		ajaxFileUpload();
	});
}
upload();







// 默认的省市
var pid = $('.Country_input').attr('data-Country')
var cid = $('.City_input').attr('data-City')
$.ajax({
	url: URL+'area/ajax_list_children',
	type: 'GET',
	dataType: 'json',
	data: {
		parent_id: 0
	},
	success: function(data) {
		var data = data.content;
		for (var i = 0; i < data.data.length; i++) {
			$('.Country_input').append('<option data-id="' + data.data[i].short_name + '"  value ="'+data.data[i].id+'">'+data.data[i].short_name+'</option>');
		}
		$(".Country_input").find("option[value=" + pid +"]").attr('selected', 'selected');
		// var defaultpid = $('.Country_input').find("option:selected").attr('data-id')
		citys(pid)

	}
	
})

$('.Country_input').change(function(event) {
	var pid = $(this).find("option:selected").val()
	citys(pid)
});
var citys = function(pid) {

	$.ajax({
		url: URL+'area/ajax_list_children/' + pid,
		type: 'GET',
		dataType: 'json',
		success: function(data) {
			var data = data.content;
			$('.City_input').html('')
			for (var i = 0; i < data.data.length; i++) {
				$('.City_input').append('<option data-id="' + data.data[i].short_name + '"  value ="'+data.data[i].id+'">'+data.data[i].short_name+'</option>');
			}

			$(".City_input").find("option[value=" + cid +"]").attr('selected', 'selected');
		}
	})
}

// 文本框默认


// Notice of participation
// var Noticeofparticipation_con = "Fill in the number of reservations\nage limit \nWeight limit \nWhether a driver's license is required \nAre there any additional precautions?"
tex($('.Noticeofparticipation_con'),lang.Noticeofparticipation_con)

// Voucher information
// var Voucherinformation_con = "Example：You can present either a paper or an electronic voucher for this activity."
tex($('.Voucherinformation_con'),lang.Voucherinformation_con)

// var CancellationPolicy_con = "Example：\nIf you cancel at least 7 day(s) in advance of the scheduled departure, there is no cancellation fee.\nIf you ncel between 3 and 6 day(s) in advance of the scheduled departure, there is a 50 percent cancellation fee.\nIf you ncel within 2 day(s) of the scheduled departure, there is a 100 percent cancellation fee."
tex($('.CancellationPolicy_con'),lang.CancellationPolicy_con)




// var Exclusions_con = "Example：\nOptional gratuities\nHotel pickup and drop-off\nFood and drinks, unless specified\nEntrance to monuments and seums"
tex($('.Exclusions_con'),lang.Exclusions_con)


// var Inclusions_con = "Example：\nOrientation session (30 minutes)\nSegway tour with audio-guide (3 hours)\nTour leader\nHeadphones so you can ar the audio guide and tour leader clearly\nWet weather jackets"
tex($('.Inclusions_con'),lang.Inclusions_con)

// var Routeintroduction_con = "Enter Detail introduction of this tour.\nIncluding things to do every time, all the attractions in this tour."
tex($('.Routeintroduction_con'),lang.Routeintroduction_con)

// var Departuretime_con = "Enter How long ahead of time"
tex($('.Departuretime_con'),lang.Departuretime_con)

// var  Businesshours_con = "Enter Monday to Sunday to commute time"
tex($('.Businesshours_con'),lang.Businesshours_con)

// var Highlights_con = "Example：\nSmall-group tour\nChoice of morning or afternoon departure\nIdeal choice for families"
tex($('.Highlights_con'),lang.Highlights_con)


// var Location_con = "Enter place to meet";
tex($('.Location_con'),lang.Location_con)




function tex(el, con) {
	// el.val(con);


	el.focus(function() {
		if ($(this).val() == con) {
			$(this).val('');
		}
	});
	el.blur(function() {
		if ($(this).val() == '') {
			$(this).val(con);
		}
	});
	if (el.val() == con) {
		el.addClass('textareacolor')
	} else {
		el.removeClass('textareacolor')
	}
}
$('textarea').keydown(function(event) {
	$(this).removeClass('textareacolor')
})


// 修改添加保存
$('#submit_btn').click(function() {


	$.ajax({
		url: URL+'business/touroute/ajax_create',
		type: 'POST',
		data: $('#form').serialize(),
		success:function(data){
			var datas= JSON.parse(data)

			alert(datas.message)

		}
	})

	
	
	
});


